import Vue from 'vue';
import VueRouter from 'vue-router';
//import VueMeta from 'vue-meta';
import Vuex from 'vuex';
// 入口文件为 src/App.vue 文件 所以要引用
import App from './App.vue';
import Flex from 'lib-flexible';
// 引用路由配置文件
import routes from './config/routes';
// 引入api.js
import api from './config/api';
import {bus} from "./config/bus";
import axios from 'axios';
import qs from 'qs';
import store from './vuex/store'
//import  'my-components';
// 图片略缩放大插件
//import vuePicturePreview from 'vue-picture-preview';
//import alertTip from './page/public/alertTip.vue';
//import CPdf from './components/pdf.vue';
import swiper from './components/swiper.vue';
import bottomTab from './components/bottom.vue';
import hangCard from './components/hangCard.vue';

//import pop from './components/pop.vue';
import Trans from './script/transMd5.js';
import jquery from 'jQuery';
// 轮播插件
import VueAwesomeSwiper from 'vue-awesome-swiper';
import VueWechatTitle from 'vue-wechat-title'

// 日期格式化插件
import { formatDate } from '../src/script/formDate';
// 绑定api 到全局
Vue.prototype.$api = api;
Vue.prototype.$ajax = axios;
Vue.prototype.$qs = qs;
Vue.prototype.$ = jquery;
Vue.prototype.bus = bus;
// 光引用不成，还得使用
Vue.use(VueRouter);
Vue.use(Flex);
//Vue.use(VueMeta);
//Vue.use(vuePicturePreview);
//Vue.use(Vuex);
Vue.use(Trans);
Vue.use(VueAwesomeSwiper);
Vue.use(VueWechatTitle)
//Vue.component('alert-tip', alertTip);
//Vue.component(CPdf.name, CPdf)
Vue.component(swiper.name, swiper);
Vue.component(bottomTab.name, bottomTab);
Vue.component(hangCard.name, hangCard);
//Vue.use(require('vue-wechat-title'));
//Vue.component(pop.name, pop);
// 使用配置文件规则
const router = new VueRouter({
  routes,
	mode: 'history'  
});
// 保留1位小数点过滤器
Vue.filter('numberOne', function (value) {
  if (value) {
    return value.toFixed(1);
  }
});
// 保留2位小数点过滤器 不四舍五入
Vue.filter('number', function (value) {
  var realVal = value.toFixed(3).substring(0, value.toFixed(3).toString().length - 1);
  return realVal;
});
// 判断万元
Vue.filter('numberFour', function (value) {
  if (value) {
    var aVal;
    if (value.toString().length > 4) {
      aVal = value / 10000;
    } else {
      aVal = value;
    }
    var realVal = aVal.toFixed(3).substring(0, aVal.toFixed(3).toString().length - 1);
    return realVal;
  }
});
Vue.filter('numberUnit', function (value) {
  if (value) {
    var aVal;
    if (value.toString().length > 4) {
      return '万元';
    } else {
      return '元';
    }
  }
});
Vue.filter('dateFormat', function (time) {
  var date = new Date(time);
  return formatDate(date, 'yyyy-MM-dd');
});
// 路由判断登录，回跳
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
    if (localStorage.getItem('sid')) {
      next();
    } else {
      next({
        path: '/yylc-h5/login/login-tel',
        query: {
          redirect: to.fullPath
        } // 将跳转的路由path作为参数，登录成功后跳转到该路由
      });
    }
  } else {
    next();
  }
});
//router.afterEach((transition)=>{
// 	let name = transition.name;
// 	let item = router.options.routes.filter((ele)=>{ return ele.name == name});
//// 	document.title = item[0].title;
//// 	        if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
////          const hackIframe = document.createElement('iframe');
////          //hackIframe.style.display = 'none';
////          hackIframe.src = '../../iosTitle.html?r=' + Math.random();
////          document.body.appendChild(hackIframe);
////          setTimeout(_ => {
////              document.body.removeChild(hackIframe)
////          }, 300)
////      }
//})
/* eslint-disable no-new */
new Vue({
  router,
  store,
  el: '#app',
  render: (h) => h(App)
});
